/**
 * create by young (young2f@outlook.com) on 2020/12/4
 * 实际没有真实的数据
 * 是为了过滤采购单
 */
'use strict';
const model = require('../base/tModelBase');
const _ = require('lodash');
module.exports = app => {
  const mongoose = app.mongoose;
  const schema = mongoose.Schema;
  const connect = app.mongooseDB.get('pmcBus');
  const json = {
    code: {
      type: 'string',
      _type: 'string',
      table: 'material',
      title: '采购单编码',
      required: true,
      disabled: true,
      enableArea: [
        'table',
        'detail',
        'search'
      ]
    },
    division: {
      type: 'string', _type: 'string', table: 'division', title: '事业部', required: true, enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },

    vendor: {
      type: 'string', _type: 'string', title: '供应商名称', enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },
    vendorCode: {
      type: 'string', _type: 'code', title: '供应商编码', required: true, enableArea: []
    },
    count: {
      type: 'number', _type: 'number', title: '数量', enableArea: [
        'table', 'input',
        'detail',
      ], default: 0
    },

    materials: {
      type: 'array', _type: 'array', table: 'material', title: '物料列表', required: true, enableArea: [
        'table', 'input',

      ]
    },
    amount: {
      type: 'number', _type: 'number', title: '金额', enableArea: [
        'table', 'detail',
      ], default: 0
    },
    inboundCount: {
      type: 'number', _type: 'number', title: '入库数量', enableArea: [
        'table', 'input',
        'detail',
        'search'
      ]
    },

  };
  const _model = _.cloneDeep(model);
  _.assign(_model, json);
  const _schema = new schema(
    _model,
    { timestamps: { createdAt: 'createdTs', updatedAt: 'updatedTs' } }
  );
  _schema.index({ 'code': 1 });
  return connect.model('InboundOrder', _schema);
};
/**
 current: { type: 'number' },
 voltage: { type: 'number' },
 activePower: { type: 'number' },
 positiveActiveEnergy: { type: 'number' },
 ReverseActiveEnergy: { type: 'number' },
 currentA: { type: 'number' },
 currentB: { type: 'number' },
 currentC: { type: 'number' },
 voltageA: { type: 'number' },
 voltageB: { type: 'number' },
 voltageC: { type: 'number' },
 */
